package com.tzbank.common.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.tzbank.common.dao.UserMapper;
import com.tzbank.common.entity.User;
import com.tzbank.common.param.UserParam;
import com.tzbank.common.service.UserInfoService;

@Service
public class UserInfoServiceImpl implements UserInfoService {

	@Resource
	private UserMapper userMapper;

	@Override
	public Map<String, Object> findUserByUserName(UserParam userParam) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", false);
		if (StringUtils.isEmpty(userParam.getUserName())) {
			map.put("info", "请输入用户名");
			return map;
		}
		if (StringUtils.isEmpty(userParam.getPassword())) {
			map.put("info", "请输入密码");
			return map;
		}

		User user = userMapper.findUserByName(userParam.getUserName().trim());
		if (user == null) {
			map.put("info", "用户不存在");
			return map;
		}

		if (!user.getPassword().equals(userParam.getPassword())) {
			map.put("info", "密码不正确，请重新输入");
			return map;
		}
		map.put("success", true);
		map.put("user", user);
		map.put("info", "登陆成功");
		return map;
	}
}
